/*
 * Create Author  : jinpeng.chen
 * Create Date    : 2016-11-22
 * Project        : spring-boot
 * File Name      : AwareService.java
 *
 * Copyright (c) 2010-2015 by Shanghai HanTao Information Co., Ltd.
 * All rights reserved.
 *
 */
package com.charles.spring.service;

import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * 功能描述:  <p>
 *
 * @author : jinpeng.chen <p>
 * @version 1.0 2016-11-22
 * @since spring-boot 1.0
 */
@Service
public class AwareService implements BeanNameAware,ResourceLoaderAware {
    private String beanName;
    private ResourceLoader resourceLoader;


    public void output() throws IOException {
        System.out.println("beanName: " + beanName);
        Resource resource = resourceLoader.getResource("classpath:test.txt");
        System.out.println(IOUtils.toString(resource.getInputStream()));
    }
    
    public void setBeanName(String s) {
        this.beanName = s;
    }

    public void setResourceLoader(ResourceLoader resourceLoader) {
        this.resourceLoader = resourceLoader;
    }
}
